package com.amap.location.demo;

import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;


import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;

import org.qtproject.qt5.android.bindings.QtActivity;

public class MainActivity extends QtActivity implements AMapLocationListener{


    private LocationManagerProxy mLocationManagerProxy;

    private static String dingwei = null;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }
    
    private void init() {
        
        mLocationManagerProxy = LocationManagerProxy.getInstance(this);
 
        mLocationManagerProxy.requestLocationData(
                LocationProviderProxy.AMapNetwork, 60*1000, 15, this);
 
        mLocationManagerProxy.setGpsEnable(false);
    }

	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onLocationChanged(AMapLocation amapLocation) {
		// TODO Auto-generated method stub
		String msg;
		if(amapLocation != null && amapLocation.getAMapException().getErrorCode() == 0){

            Double geoLat = amapLocation.getLatitude();
            Double geoLng = amapLocation.getLongitude();  
            String location = amapLocation.getAddress();
            
            msg = geoLat+" "+geoLng+location;

             Log.d("local_test_for", msg);
             dingwei = msg;
        }
		
	}
	
	@Override
	protected void onPause() {
		super.onPause();

		mLocationManagerProxy.removeUpdates(this);
		mLocationManagerProxy.destroy();
	}

	protected void onDestroy() {
		super.onDestroy();

        }

        public static String send_data()
        {
            return dingwei;
        }
}
	
	
    
    

